#include "bounding-sphere.hh"

BoundingSphere::BoundingSphere (const Vector3f& pos, const Vector3f& size)
  : Bounding (pos, Vector3d (), size)
{
}

BoundingSphere::~BoundingSphere ()
{
}

bool BoundingSphere::intersect (Bounding* obj)
{
  if ((*obj) () == SPHERE)
  {
    // First step => main bounding collision
    // To avoid dynamic cast => costly and we're sure that it's a sphere !
    BoundingSphere* sph = (BoundingSphere*) obj;
    double collision_distance = size_ (0) + sph->size () (0);
    Vector3f other_pos = sph->pos ();
    Vector3f buff = other_pos - pos_;

    double distance = buff.get_norme ();
    if (distance < collision_distance)
     return true;
  }
  return false;
}

bool
BoundingSphere::intersectWall (Plane& p)
{
  return std::abs (p.distanceToPoint (pos_)) <= size_ (0);
}

int BoundingSphere::operator() ()
{
  return SPHERE;
}
